package com.neo.push.server.handler;

import com.neo.push.core.PingMessage;
import com.neo.push.core.PongMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by lock on 17-7-11.
 */
public class ServerHearBeatHandler extends ChannelInboundHandlerAdapter {

    private Logger logger = LoggerFactory.getLogger(ServerHearBeatHandler.class);


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if(msg instanceof PingMessage){
            logger.info(" ctx :"+ctx.channel().id().asShortText()+" ping message, response pong !");
            ctx.writeAndFlush(new PongMessage());
        }else{
            super.channelRead(ctx,msg);
        }
    }


}
